/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.doeacc.tms.service.dao;

import java.util.List;
import javax.annotation.security.RolesAllowed;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.criteria.CriteriaQuery;

import edu.doeacc.tms.domain.Role;
import edu.doeacc.tms.domain.User;

/**
 *
 * @author slok
 */
@Stateless
public class UserFacade extends AbstractFacade<User> {

    @PersistenceContext(unitName = "tms_pu")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public UserFacade() {
        super(User.class);
    }

    @RolesAllowed("administrator")
    public List<Role> findAllRoles() {
        CriteriaQuery cq = getEntityManager().getCriteriaBuilder().createQuery();
        cq.select(cq.from(Role.class));
        return getEntityManager().createQuery(cq).getResultList();
    }

  
    public Role findRole(Object id) {
         return getEntityManager().find(Role.class, id);
    }

   
    @RolesAllowed("administrator")
    @Override
    public void create(User entity) {
        super.create(entity);
    }

    
    @RolesAllowed("administrator")
    @Override
    public void edit(User entity) {
        super.edit(entity);
    }

    public void editSelf(User entity) {
        super.edit(entity);
    }
   
    @RolesAllowed("administrator")
    @Override
    public void remove(User entity) {
        super.remove(entity);
    }
}
